package id.net.iconpln.bb.client.view;

import id.net.iconpln.bb.client.model.BeanModelMasterBb;
import id.net.iconpln.bb.client.service.MasterRPCService;
import id.net.iconpln.bb.client.service.MasterRPCServiceAsync;
import id.net.iconpln.bb.client.util.ClientModule;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.core.FastMap;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
import com.extjs.gxt.ui.client.widget.layout.FitData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class PageBbMasterPemasok extends LayoutContainer {
	private final MasterRPCServiceAsync masterService = GWT.create(MasterRPCService.class);
	
	private Grid grid, gridkit, gridTransportir;
	private EditorGrid gridkitList, gridTransportirList;
	private ListStore storePembangkit, storePembangkitList, store, storeTransportir, storeTransportirList;
	private Button btupdate, btdelete, btnSavePemasok, btnSaveTransportir;
	private Button btnAddPembangkit, btnDelPembangkit;
	private Button btnAddTransportir, btnDelTransportir;
	
	private Window windowPemasok, windowPembangkit, windowTransportir;
	
	ToolBar toolbar = new ToolBar();
	ToolBar toolbar1 = new ToolBar();
	ToolBar toolbar2 = new ToolBar();
     
	@Override
	protected void onRender(Element parent, int pos) {
	    super.onRender(parent, pos); 
	    setLayout(new FitLayout());  
	    ContentPanel cp = new ContentPanel();  
	    cp.setHeading("Master Pembangkit");  
	    cp.setFrame(true);  
	    cp.setLayout(new RowLayout(Orientation.HORIZONTAL));  
	    
	    createGridPemasok();
	    
	    Button btnNewPemasok = new Button("New"); 
	    btnNewPemasok.addSelectionListener(new SelectionListener<ButtonEvent>() {  
	  	  
	      @Override  
	      public void componentSelected(ButtonEvent ce) {  
	    	  windowPemasok.show();
	      }  
	  
	    });
	    btnNewPemasok.setIcon(IconHelper.createStyle("icon-contact-add"));
	    
	    btupdate = new Button("Edit", new SelectionListener<ButtonEvent>() {  
	    	@Override  
	    	public void componentSelected(ButtonEvent ce) {
	    	}  
      	});  
	    btupdate.setIcon(IconHelper.createStyle("icon-reza-edit"));
	    
	    btdelete = new Button("Delete", new SelectionListener<ButtonEvent>() {  
	    	@Override  
	    	public void componentSelected(ButtonEvent ce) {
	    	}  
	    });  
	    btdelete.setIcon(IconHelper.createStyle("icon-reza-delete"));
	    	    
	    ContentPanel cpPemasok = new ContentPanel();
	    cpPemasok.setHeaderVisible(false);
	    cpPemasok.add(grid);
	    cpPemasok.setLayout(new FitLayout());
	    toolbar.add(new LabelToolItem("Daftar Pemasok"));
	    toolbar.add(new SeparatorToolItem());
	    toolbar.add(btnNewPemasok);
		toolbar.add(new SeparatorToolItem());
	    toolbar.add(btupdate);
		toolbar.add(new SeparatorToolItem()); 
		toolbar.add(btdelete);
	    cpPemasok.setTopComponent(toolbar);
	    	    
	    createGridkit();
	    btnAddPembangkit = new Button("Add");  
	    btnAddPembangkit.addSelectionListener(new SelectionListener<ButtonEvent>() { 
	      @Override  
	      public void componentSelected(ButtonEvent ce) {  
	    	  if (!(grid.getSelectionModel().getSelectedItem() == null)){
	    		  getdataKitOut(grid.getSelectionModel().getSelectedItem().get("id_pemasok").toString());
	    	  }
	      }  
	    });
	    btnAddPembangkit.setIcon(IconHelper.createStyle("icon-contact-add"));
	    
	    btnDelPembangkit = new Button("Remove");  
	    btnDelPembangkit.addSelectionListener(new SelectionListener<ButtonEvent>() { 
	    	@Override  
	    	public void componentSelected(ButtonEvent ce) {  
	    	  
	    	}  
	    });
	    
	    ContentPanel panPembangkit = new ContentPanel();
	    panPembangkit.setHeaderVisible(false);
	    panPembangkit.setLayout(new FitLayout());
	    panPembangkit.add(gridkit);
	    toolbar2.add(new LabelToolItem("Daftar Pembangkit"));
	    toolbar2.add(new SeparatorToolItem());
	    toolbar2.add(btnAddPembangkit);
	    toolbar2.add(new SeparatorToolItem());
	    toolbar2.add(btnDelPembangkit);
	    panPembangkit.setTopComponent(toolbar2);
	    
	  
	    createGridTransportir(); 
	    btnAddTransportir = new Button("Add");  
	    btnAddTransportir.addSelectionListener(new SelectionListener<ButtonEvent>() { 
	      @Override  
	      public void componentSelected(ButtonEvent ce) {  
	    	  if (!(grid.getSelectionModel().getSelectedItem() == null)){
	    		  getdataTransOut(grid.getSelectionModel().getSelectedItem().get("id_pemasok").toString());
	    	  }
	      }  
	    });
	    btnAddTransportir.setIcon(IconHelper.createStyle("icon-contact-add"));
	    
	    btnDelTransportir = new Button("Remove");  
	    btnDelTransportir.addSelectionListener(new SelectionListener<ButtonEvent>() { 
	    	@Override  
	    	public void componentSelected(ButtonEvent ce) {  
	    	  
	    	}  
	    });
	    
	    ContentPanel panTransportir = new ContentPanel();
	    panTransportir.setHeaderVisible(false);
	    panTransportir.setLayout(new FitLayout());
	    panTransportir.add(gridTransportir);
	    toolbar1.add(new LabelToolItem("Daftar Transportir"));
	    toolbar1.add(new SeparatorToolItem());
	    toolbar1.add(btnAddTransportir);
	    toolbar2.add(new SeparatorToolItem());
	    toolbar1.add(btnDelTransportir);
	    panTransportir.setTopComponent(toolbar1);
	    
	    ContentPanel panel = new ContentPanel();
	    panel.setHeaderVisible(false);
	    panel.setLayout(new RowLayout(Orientation.VERTICAL));
	    panel.add(panPembangkit, new RowData(1, .33));
	    panel.add(panTransportir, new RowData(1, .33));
		   
	    ContentPanel delimeter = new ContentPanel();
	    delimeter.setHeaderVisible(false);
	    delimeter.setWidth(10);
	   
	    cp.add(cpPemasok, new RowData(.5, 1));
	    cp.add(delimeter, new FitData(5));
	    cp.add(panel, new RowData(.5, 1));  
	    add(cp, new FitData(5));  
	    
	    createFormPemasok();
	}  
	  
	private void createGridkit() {  	    
		final List<ColumnConfig> columns = new ArrayList<ColumnConfig>(); 	    
		storePembangkit = new ListStore<BeanModelMasterBb>();		
		RowNumberer id = new RowNumberer();  
	    id.setWidth(30);
	    
	    ColumnConfig nmkit = new ColumnConfig("nama_pembangkit", "Nama Pembangkit", 250);
	    nmkit.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig nmpic = new ColumnConfig("nama_pic", "Nama PIC", 120);
	    nmpic.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig alamat = new ColumnConfig("alamat", "Alamat", 100);
	    alamat.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig pemilik = new ColumnConfig("kepemilikan", "Pemilik", 100);
	    pemilik.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig wilayah = new ColumnConfig("wilayah", "Wilayah", 130);
	    wilayah.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig jeniskit = new ColumnConfig("jenis_pembangkit", "Jenis Pembangkit", 130);
	    jeniskit.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig tlp = new ColumnConfig("telp", "Telp", 130);
	    tlp.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig daya = new ColumnConfig("daya_terpasang", "Daya Terpasang", 130);
	    daya.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig sfc = new ColumnConfig("sfc", "SFC", 130);
	    sfc.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig capacity_F = new ColumnConfig("capacity_factor", "Capacity Factor", 130);
	    capacity_F.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig hear_rate = new ColumnConfig("heat_rate", "Heat Rate", 130);
	    hear_rate.setAlignment(HorizontalAlignment.LEFT);
	    
	    columns.add(nmkit);
	    columns.add(jeniskit);
	    columns.add(daya);
	    columns.add(pemilik);
	    columns.add(alamat);
	    columns.add(wilayah);
	    columns.add(nmpic);
	    columns.add(sfc);
	    columns.add(capacity_F);
	    columns.add(hear_rate); 
	  
	    final ColumnModel cm = new ColumnModel(columns);	    
	    gridkit = new Grid(storePembangkit, cm);
	    gridkit.setBorders(true); 
	    
	    final List<ColumnConfig> columnsList = new ArrayList<ColumnConfig>(); 
	    CheckColumnConfig checkColumn = new CheckColumnConfig("selectPembangkit", "Select", 55); 
	    CheckBox cb = new CheckBox();
	    cb.setValue(true);
	    CellEditor checkBoxEditor = new CellEditor(cb);  
	    checkColumn.setEditor(checkBoxEditor);  
	    columnsList.add(checkColumn);
	    columnsList.add(nmkit);
	    final ColumnModel cmList = new ColumnModel(columnsList);
	    btnSavePemasok = new Button("Save");
	    
	    ToolBar toolbarListPemasok = new ToolBar();
	    toolbarListPemasok.add(btnSavePemasok);
	    
	    storePembangkitList = new ListStore();
	    gridkitList = new EditorGrid(storePembangkitList, cmList);
	    gridkitList.setBorders(true); 
	    gridkitList.setHeight(280);
	    
	    windowPembangkit = new Window();  
	    windowPembangkit.setHeading("List Pembangkit");
	    windowPembangkit.setSize(400, 300);
	    windowPembangkit.add(gridkitList);
	    windowPembangkit.setTopComponent(toolbarListPemasok);
	    
  }
		  
	private void createGridPemasok() {  
		store = new ListStore<BeanModelMasterBb>();
		getdataPemasok();			
		RowNumberer rn = new RowNumberer();  
		rn.setWidth(30);
		
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
			 
		ColumnConfig 	id_pemasok	 = new ColumnConfig("id_pemasok", "id pemasok", 150);
	    id_pemasok.setAlignment(HorizontalAlignment.LEFT);
	    id_pemasok.setHidden(true);
			    
	    ColumnConfig 	pemasok	 = new ColumnConfig("pemasok", "Pemasok", 150);
	    pemasok.setAlignment(HorizontalAlignment.LEFT);
			    
	    ColumnConfig 	alamat	 = new ColumnConfig("alamat", "Alamat", 150);
	    alamat.setAlignment(HorizontalAlignment.LEFT);
			    
	    ColumnConfig 	pic_presdir	 = new ColumnConfig("pic_presdir", "PIC Pres Dir", 150);
	    pic_presdir.setAlignment(HorizontalAlignment.LEFT);
			    
	    ColumnConfig 	pic_dir_marketing	 = new ColumnConfig("pic_dir_marketing", "PIC Dir Marketing", 150);
	    pic_dir_marketing.setAlignment(HorizontalAlignment.LEFT);

	    ColumnConfig 	pic_man_opr	 = new ColumnConfig("pic_man_opr", "PIC Mgr Operasi", 150);
	    pic_man_opr.setAlignment(HorizontalAlignment.LEFT);
			    
	    ColumnConfig 	status_pemasok	 = new ColumnConfig("status_pemasok", "Status Pemasok", 150);
	    status_pemasok.setAlignment(HorizontalAlignment.LEFT);
			    
	    ColumnConfig 	nama_tambang	 = new ColumnConfig("nama_tambang", "Nama Tambang", 150);
	    nama_tambang.setAlignment(HorizontalAlignment.LEFT);
			    
	    ColumnConfig 	produksi	 = new ColumnConfig("produksi", "Produksi", 150);
	    produksi.setAlignment(HorizontalAlignment.LEFT);
			    
	    ColumnConfig 	loading_port	 = new ColumnConfig("loading_port", "Loading Port", 150);
	    loading_port.setAlignment(HorizontalAlignment.LEFT);
			    
	    ColumnConfig 	fasilitas_loading	 = new ColumnConfig("fasilitas_loading", "Fasilitas Loading", 150);
	    fasilitas_loading.setAlignment(HorizontalAlignment.LEFT);
			
	    ColumnConfig 	jarak_hauling	 = new ColumnConfig("jarak_hauling", "Jarak Hauling", 150);	    
	    jarak_hauling.setAlignment(HorizontalAlignment.LEFT);
			    
	    ColumnConfig 	flag_blacklist	 = new ColumnConfig("flag_blacklist", "Flag Blacklist", 150);
	    flag_blacklist.setAlignment(HorizontalAlignment.LEFT);
			    
	    ColumnConfig 	status_aktif	 = new ColumnConfig("status_aktif", "Status Aktif", 150);
	    status_aktif.setAlignment(HorizontalAlignment.LEFT);
			    
	    ColumnConfig 	keterangan	 = new ColumnConfig("keterangan", "Keterangan", 150);
	    keterangan.setAlignment(HorizontalAlignment.LEFT);				
				
		columns.add(rn);
		columns.add(id_pemasok);
		columns.add(pemasok);
		columns.add(alamat);
		columns.add(pic_presdir);
		columns.add(pic_dir_marketing);
		columns.add(pic_man_opr);
		columns.add(status_pemasok);
		columns.add(nama_tambang);
		columns.add(produksi);
		columns.add(loading_port);
		columns.add(fasilitas_loading);
		columns.add(jarak_hauling);
		columns.add(flag_blacklist);
		columns.add(status_aktif);
		columns.add(keterangan);
			  
	    final ColumnModel cm = new ColumnModel(columns);
			    
	    grid = new Grid(store, cm);  
	    grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); 
	    grid.addListener(Events.CellClick, new Listener<BaseEvent>() {            
            public void handleEvent(BaseEvent ge) {
            	getdataKit(grid.getSelectionModel().getSelectedItem().get("id_pemasok").toString());
            	getdataTrans(grid.getSelectionModel().getSelectedItem().get("id_pemasok").toString());
            }
        });
}  

	private void createGridTransportir() {  
	    
		final List<ColumnConfig> columns = new ArrayList<ColumnConfig>();     
		storeTransportir = new ListStore<BeanModelMasterBb>();
		RowNumberer id = new RowNumberer();  
	    id.setWidth(30);
    
	    ColumnConfig namatransportir = new ColumnConfig("nama_transportir", "Nama Transportir", 200);
	    namatransportir.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig alamat = new ColumnConfig("alamat", "Alamat", 200);
	    alamat.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig telp = new ColumnConfig("telp", "Telp", 80);
	    telp.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig pic = new ColumnConfig("pic", "PIC", 80);
	    pic.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig namatransport = new ColumnConfig("nama_transport", "Nama Transport", 200);
	    namatransport.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig jenistransport = new ColumnConfig("jenis_transport", "Jenis Transport", 200);
	    jenistransport.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig kodetransport = new ColumnConfig("kode_transport", "Kode Transport", 100);
	    kodetransport.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig jumlahkapal = new ColumnConfig("jumlah_kapal", "Jumlah Kapal", 80);
	    jumlahkapal.setAlignment(HorizontalAlignment.LEFT);
	    
	    ColumnConfig speckapal = new ColumnConfig("spec_kapal", "Spesifikasi Kapal", 100);
	    speckapal.setAlignment(HorizontalAlignment.LEFT);
	    
	    columns.add(id);
	    columns.add(namatransportir);
	    columns.add(alamat);
	    columns.add(pic);
	    columns.add(namatransport);
	    columns.add(jenistransport);
	    columns.add(kodetransport);
	    columns.add(jumlahkapal);
	    columns.add(speckapal);
	    
	    final ColumnModel cm = new ColumnModel(columns);	    
	    gridTransportir = new Grid(storeTransportir, cm);
	    gridTransportir.setBorders(true); 

	    
	    final List<ColumnConfig> columnsList = new ArrayList<ColumnConfig>(); 
	    CheckColumnConfig checkColumn = new CheckColumnConfig("selectTransportir", "Select", 55); 
	    CheckBox cb = new CheckBox();
	    cb.setValue(true);
	    CellEditor checkBoxEditor = new CellEditor(cb);  
	    checkColumn.setEditor(checkBoxEditor);  
	    columnsList.add(checkColumn);
	    columnsList.add(namatransportir);
	    final ColumnModel cmList = new ColumnModel(columnsList);
	    btnSaveTransportir = new Button("Save");
	    
	    ToolBar toolbarListPemasok = new ToolBar();
	    toolbarListPemasok.add(btnSaveTransportir);
	    
	    storeTransportirList = new ListStore();
	    gridTransportirList = new EditorGrid(storeTransportirList, cmList);
	    gridTransportirList.setBorders(true); 
	    gridTransportirList.setHeight(280);
	    
	    windowTransportir = new Window();  
	    windowTransportir.setHeading("List Transportir");
	    windowTransportir.setSize(400, 300);
	    windowTransportir.add(gridTransportirList);
	    windowTransportir.setTopComponent(toolbarListPemasok);
	    
	}  

	private void createFormPemasok(){
		FormPanel simple = new FormPanel();  
	    simple.setHeaderVisible(false);
	    simple.setFrame(true);
	    simple.setWidth(350);
	    
	    FieldSet fieldSet = new FieldSet();  
	    fieldSet.setHeading("Identitas Pemasok");  
	    fieldSet.setCollapsible(false);
	    
	    FormLayout layout = new FormLayout();  
	    layout.setLabelWidth(120);  
	    fieldSet.setLayout(layout);
	    
	    FieldSet fieldSet1 = new FieldSet();  
	    fieldSet1.setHeading("Informasi Pemasok");  
	    fieldSet1.setCollapsible(false);
	    
	    FormLayout layout1 = new FormLayout();  
	    layout1.setLabelWidth(120);  
	    fieldSet1.setLayout(layout1);
	    
	    FieldSet fieldSet2 = new FieldSet();  
	    fieldSet2.setHeading("Informasi Tambahan (PIC)");  
	    fieldSet2.setCollapsible(false);
	    
	    FormLayout layout2 = new FormLayout();  
	    layout2.setLabelWidth(120);  
	    fieldSet2.setLayout(layout2);
	    
	    final TextField<String> txtnmpemasok = new TextField<String>(); 
	    txtnmpemasok.setFieldLabel("Nama Pemasok");
	    txtnmpemasok.setMaxLength(100);
	    fieldSet.add(txtnmpemasok);  
	    
	    
	    final TextField<String> txtalamat = new TextField<String>(); 
	    txtalamat.setFieldLabel("Alamat");
	    txtalamat.setMaxLength(100);
	    fieldSet.add(txtalamat); 
	    
	    
	    final TextField<String> txtstatus = new TextField<String>(); 
	    txtstatus.setFieldLabel("Status");
	    txtstatus.setMaxLength(100);
	    fieldSet.add(txtstatus); 
	    
	    final TextField<String> txtidpusat = new TextField<String>(); 
	    txtidpusat.setFieldLabel("Id Pusat");
	    txtidpusat.setMaxLength(100);
	    txtidpusat.setVisible(false);
	    fieldSet.add(txtidpusat); 
	    
	    final TextField<String> txttelp = new TextField<String>(); 
	    txttelp.setFieldLabel("Telp");
	    txttelp.setMaxLength(100);
	    fieldSet.add(txttelp); 
	    
	    final TextField<String> txtfax = new TextField<String>(); 
	    txtfax.setFieldLabel("Fax");
	    txtfax.setMaxLength(100);
	    fieldSet.add(txtfax); 
	    
	    final TextField<String> txtemail = new TextField<String>(); 
	    txtemail.setFieldLabel("Email");
	    txtemail.setMaxLength(100);
	    fieldSet.add(txtemail); 
	    
	    final TextField<String> txtstatuspemasok = new TextField<String>(); 
	    txtstatuspemasok.setFieldLabel("Status Pemasok");
	    txtstatuspemasok.setMaxLength(100);
	    fieldSet1.add(txtstatuspemasok); 
	    
	    final TextField<String> txtnmtambang = new TextField<String>(); 
	    txtnmtambang.setFieldLabel("Nama Tambang");
	    txtnmtambang.setMaxLength(100);
	    fieldSet1.add(txtnmtambang); 
	    
	    
	    final TextField<String> txtproduksi = new TextField<String>(); 
	    txtproduksi.setFieldLabel("Produksi");
	    txtproduksi.setMaxLength(100);
	    fieldSet1.add(txtproduksi);  
	    
	    final TextField<String> txtloadingport = new TextField<String>(); 
	    txtloadingport.setFieldLabel("Loading Port");
	    txtloadingport.setMaxLength(100);
	    fieldSet1.add(txtloadingport);  
	    
	    final TextField<String> txtfasilitasloading = new TextField<String>(); 
	    txtfasilitasloading.setFieldLabel("Fasilitas Loading");
	    txtfasilitasloading.setMaxLength(100);
	    fieldSet1.add(txtfasilitasloading);  
	    
	    final TextField<String> txtjarakhauling = new TextField<String>(); 
	    txtjarakhauling.setFieldLabel("Jarak Hauling");
	    txtjarakhauling.setMaxLength(100);
	    fieldSet1.add(txtjarakhauling);  
	    
	    final TextField<String> txtket = new TextField<String>(); 
	    txtket.setFieldLabel("Keterangan");
	    txtket.setMaxLength(100);
	    fieldSet1.add(txtket);  
	    
	    final TextField<String> txtpicpresdir = new TextField<String>(); 
	    txtpicpresdir.setFieldLabel("PIC Presdir");
	    txtpicpresdir.setMaxLength(100);
	    fieldSet2.add(txtpicpresdir); 
	    
	    final TextField<String> txtpicpresdirhp = new TextField<String>(); 
	    txtpicpresdirhp.setFieldLabel("PIC Presdir HP");
	    txtpicpresdirhp.setMaxLength(100);
	    fieldSet2.add(txtpicpresdirhp); 
	    
	    final TextField<String> txtpicdirmarket = new TextField<String>(); 
	    txtpicdirmarket.setFieldLabel("PIC Dir Marketing");
	    txtpicdirmarket.setMaxLength(100);
	    fieldSet2.add(txtpicdirmarket); 
	    
	    final TextField<String> txtpicdirmarkethp = new TextField<String>(); 
	    txtpicdirmarkethp.setFieldLabel("PIC Dir Marketing HP");
	    txtpicdirmarkethp.setMaxLength(100);
	    fieldSet2.add(txtpicdirmarkethp);  
	    
	    final TextField<String> txtpicmanopr = new TextField<String>(); 
	    txtpicmanopr.setFieldLabel("PIC Man Operasi");
	    txtpicmanopr.setMaxLength(100);
	    fieldSet2.add(txtpicmanopr);  
	    
	    final TextField<String> txtpicmanoprhp = new TextField<String>(); 
	    txtpicmanoprhp.setFieldLabel("PIC Man Operasi HP");
	    txtpicmanoprhp.setMaxLength(100);
	    fieldSet2.add(txtpicmanoprhp); 
	  
	    simple.add(fieldSet);
	    simple.add(fieldSet1);
	    simple.add(fieldSet2);  
	    
	    simple.setButtonAlign(HorizontalAlignment.LEFT);  
	    simple.addButton(new Button("Cancel", new SelectionListener<ButtonEvent>() {  
	    	@Override  
	    	public void componentSelected(ButtonEvent ce) {  
	    	}  
	    }));  
	    simple.addButton(new Button("Save", new SelectionListener<ButtonEvent>() {  
	    	@Override  
	    	public void componentSelected(ButtonEvent ce) {
	    	}  
	    }));  
	    
	    simple.setButtonAlign(HorizontalAlignment.CENTER); 
	    ContentPanel cp = new ContentPanel();	    
	    cp.setHeaderVisible(false);
	    ToolBar toolbar1 = new ToolBar();  
	    cp.setTopComponent(toolbar1);
	    cp.add(simple);
	    
	    windowPemasok = new Window();  
	    windowPemasok.setHeading("New Master Pemasok");  
	    windowPemasok.setHeight(500);
	    windowPemasok.setAutoWidth(true);
	    windowPemasok.setScrollMode(Scroll.AUTO);
	    windowPemasok.add(cp);
	}
	
	private void getdataKit(String id_pemasok) {
		Map map = new FastMap();
		map.put("id_pemasok", id_pemasok);
		masterService.getMaster("KIT_BY_PEMASOK", map, new AsyncCallback<List<Map>>() {
			
			@Override
			public void onSuccess(List<Map> result) {
				// TODO Auto-generated method stub
				storePembangkit.removeAll();
				storePembangkit.add(ClientModule.setListBaseModelFromListMap(result));
			}
			
			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub				
			}
		});
	}
	
	private void getdataKitOut(String id_pemasok) {
		Map map = new FastMap();
		map.put("id_pemasok", id_pemasok);
		masterService.getMaster("KIT_BY_PEMASOK_OUT", map, new AsyncCallback<List<Map>>() {
			
			@Override
			public void onSuccess(List<Map> result) {
				// TODO Auto-generated method stub
				storePembangkitList.removeAll();
				storePembangkitList.add(ClientModule.setListBaseModelFromListMap(result));
				windowPembangkit.show();
			}
			
			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub				
			}
		});
	}
	
	private void getdataTrans(String id_pemasok) {
		Map map = new FastMap();
		map.put("id_pemasok", id_pemasok);
		masterService.getMaster("TRANSPORTIR_BY_PEMASOK", map, new AsyncCallback<List<Map>>() {
			
			@Override
			public void onSuccess(List<Map> result) {
				// TODO Auto-generated method stub
				storeTransportir.removeAll();
				storeTransportir.add(ClientModule.setListBaseModelFromListMap(result));
			}
			
			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub				
			}
		});
	}
	
	private void getdataTransOut(String id_pemasok) {
		Map map = new FastMap();
		map.put("id_pemasok", id_pemasok);
		masterService.getMaster("TRANSPORTIR_BY_PEMASOK_OUT", map, new AsyncCallback<List<Map>>() {
			
			@Override
			public void onSuccess(List<Map> result) {
				// TODO Auto-generated method stub
				storeTransportirList.removeAll();
				storeTransportirList.add(ClientModule.setListBaseModelFromListMap(result));
				windowTransportir.show();
			}
			
			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub				
			}
		});
	}
	  
	private void getdataPemasok() {
		  masterService.getMaster("PEMASOK", new FastMap(), new AsyncCallback<List<Map>>() {
			
			@Override
			public void onSuccess(List<Map> result) {
				// TODO Auto-generated method stub
				store.removeAll();
				store.add(ClientModule.setListBaseModelFromListMap(result));
			}
			
			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
				
			}
		});
	  }
	  
}

